## -------------------------------------------------- #
## 00_README.txt\
## -------------------------------------------------- #\

Date: 2021-08-16

Authors: Yotam Margalit, Tara Slough, and Michael M. Ting


Title: After Defeat: How Governing Parties Respond to Electoral Loss

 Contact Information: 
   Tara Slough <tara.slough@nyu.edu>
  
	
 Copyright (c) 2021, under the Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License.
 For more information see: http://creativecommons.org/licenses/by-nc-sa/3.0/us/
 All rights reserved. 

## -------------------------------------------------- #

This file describes the contents of the replication archive used to conduct the analyses in the main text and appendix. 


## -------------------------------------------------- #
## install R and necessary packages for analysis
## -------------------------------------------------- #

open the .R files using RStudio or any text or source code editor such as:
	TextEdit, emacs, Aquamacs, notepad++ , or Xpad

set the working directory to the folder containing the data files 

the set working directory command in R is setwd()
	type ?setwd for help documentation 

to set the path type into R: 

setwd("PATH_NAME")

where PATH_NAME is the path to the mail folder

install packages if necessary:
	packages <- c("dplyr", "estimatr", "lfe", "ggplot2", "starbility")

	install.packages(packages)

You should place the folders that contain this file and the additional folders it contains into the R working directory. 

The R working directory is available via the getwd() function in R.

The attached code makes use of the file structure. As long as the folders are in the R working directory the script will find these files and work properly. 

The last version of R and Mac OS-X are:

	R version 4.2.0 (2021-06-22) -- "Taking Off Again"
	Copyright (C) 2021 The R Foundation for Statistical Computing
	Platform: x86_64-apple-darwin17.0  

## -------------------------------------------------- #
## Computer recommendations
## -------------------------------------------------- #

All models were estimated on an iMac (27-inch, 2020), running macOS Catalina (10.15.7).



## -------------------------------------------------- #
# file folder descriptions
## -------------------------------------------------- #
 
01_Codebook.pdf -- Codebook describing all variables in rtl.Rdata.

02_Replicate.R -- R code loads packages, data, and sources al code in 03_Main_text_tables_and_figures.R and 04_Appendix_tables_and_figures.R.

03_Main_text_tables_and_figures.R -- R code for all data-based tables and figures in the main text.

04_Appendix_tables_and_figures.R --  R code for all data-based tables and figures in the appendix/SI for this paaper.

05_Simulation.nb --- Mathematica file that contains the Markov chain simulation used in Figures 4-6. This code takes several hours to run so we include the output "simulation_output.csv" in the Data folder.

Data -- folder contains all cleaned data used in analysis.

Log Files -- folder contains log files for the execution of 03_Main_text_tables_andfigures.R and 04_Appendix_tables_and_figures.R
Outputs --- folder contains all figures as pdf files and table output as tex files. Note that the formatting for some tables is manually edited for aesthetic purposes. 


## -------------------------------------------------- #
# additional notes 
## -------------------------------------------------- #

Please note that Figures 3 and Tables A1, A2, and A16 do not rely on data analysis. They are therefore not reproduced by this the replication package.



## -------------------------------------------------- #
## end of file
## -------------------------------------------------- #

